// +----------------------------------------------------------------------
// | 分享组件
// +----------------------------------------------------------------------

import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/states/states_model/index.dart';

import 'wechat/WxShare.dart';

class ShareDialog {
  static Widget get widget => _Share();

  static void show(context, {String tips = "分享我们"}) {
    showModalBottomSheet(
        context: context,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(px(50)),
            topRight: Radius.circular(px(50)),
          ),
        ),
        builder: (BuildContext context) {
          return _Share(tips: tips);
        });
  }
}

class _Share extends StatefulWidget {
  _Share({this.tips, Key key}) : super(key: key);

  /// 标题提示语
  final String tips;

  @override
  __ShareState createState() => __ShareState();
}

class __ShareState extends State<_Share> {
  /// 分享按钮
  List shape = [];

  @override
  void initState() {
    super.initState();

    shape = [
      {
        'title': '朋友圈',
        'icon': 'assets/images/icon/shape1.png',
        'change': sharePyq,
      },
      {
        'title': '微信',
        'icon': 'assets/images/icon/shape2.png',
        'change': shareHy,
      },
      // {
      //   'title': 'QQ',
      //   'icon': 'assets/images/icon/shape3.png',
      //   'change': shareQq
      // },
      // {
      //   'title': 'QQ空间',
      //   'icon': 'assets/images/icon/shape4.png',
      //   'change': shareQqkj
      // },
    ];
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: px(300),
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(
              top: px(33),
            ),
            child: Text(
              '${widget.tips}',
              style: TextStyle(
                fontSize: sp(32),
                fontWeight: FontWeight.bold,
                color: col(
                  '303133',
                ),
              ),
            ),
          ),
          Container(
            width: px(683),
            margin: EdgeInsets.only(
              top: px(44),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                WxShare(
                  scene: WeChatScene.TIMELINE,
                  child: shapeicon({
                    'title': '朋友圈',
                    'icon': 'assets/images/icon/shape1.png',
                  }),
                ),
                WxShare(
                  scene: WeChatScene.SESSION,
                  child: shapeicon({
                    'title': '微信',
                    'icon': 'assets/images/icon/shape2.png',
                  }),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  // 单个分享icon
  shapeicon(item) {
    return Container(
      width: px(120),
      child: Column(
        children: <Widget>[
          Image.asset(
            item['icon'],
            width: px(88),
            height: px(88),
          ),
          Container(
            margin: EdgeInsets.only(
              top: px(27),
            ),
            child: Text(
              item['title'],
              style: TextStyle(
                fontSize: sp(22),
                color: col('303133'),
              ),
            ),
          )
        ],
      ),
    );
  }

  // 分享朋友圈
  sharePyq() {
    UserState uesr = state(context, 'user');
  }

  // 分享好友
  shareHy() {
    UserState uesr = state(context, 'user');
    // wx.shareHy(uesr.info.memberToken);
  }

  // // 分享qq
  // shareQq() {
  //   UserState uesr = state(context, 'user');
  //   qq.shareQq(uesr.info.memberToken);
  // }

  // // 分享qq空间
  // shareQqkj() {
  //   UserState uesr = state(context, 'user');
  //   qq.shareQqkj(uesr.info.memberToken);
  // }
}
